<?php
include("global_files/global_session.inc");
include("global_files/global_html.inc");
include("global_files/global_pgsql.inc");
include("global_files/global_functions.inc");
include("global_files/global_report.inc");
include("global_files/global_form.inc");

$db=new cDatabase();

if ($_POST)
	{
	$db->query="BEGIN";
	$db->runQuery();
	$farmer_array["farmer_name"]=$_POST["farmer_name"];
	$farmer_array["address1"]=$_POST["farmer_address"];
	$farmer_array["city"]=$_POST["city_id"];
	$farmer_array["village"]=$_POST["farmer_village"];
	$farmer_array["state"]=$_POST["state_id"];
	$farmer_array["language"]="ta";
	$db->query=generateInsertQuery("farmer", $farmer_array);
	$db->runQuery();
	//getting the auto generated farmer id for inserting into land farmer relation table
	$login_array["farmer_id"]=$farmer_land_array["farmer_id"]=$db->getNewId("farmer","farmer_id");	
	
	$cnt=count($_POST["land_no"]);
	
	for ($i=0; $i<$cnt; $i++)
		{
		if ($_POST["land_no"][$i]!="")
			{	
			$land_array["land_reg_number"]=$_POST["land_no"][$i];
			$land_array["land_name"]=$_POST["land_name"][$i];
			$land_array["land_address"]=$_POST["land_address"][$i];

			$land_array["land_state"]=$_POST["land_state"][$i];
			$land_array["land_city"]=$_POST["land_city"][$i];
			$land_array["land_village"]=$_POST["land_village"][$i];
			$land_array["land_size"]=$_POST["land_size"][$i];
			$land_array["uom"]=$_POST["size_uom"][$i];
			$land_array["land_size"]=$_POST["land_size"][$i];
			$db->query=generateInsertQuery("land", $land_array);
			$db->runQuery();
			//getting the auto generated land id for insertinginto land farmer relation table	
			$farmer_land_array["land_id"]=$db->getNewId("land","land_id");	
			$db->query=generateInsertQuery("farmer_land_relation", $farmer_land_array);
			$db->runQuery();
			}
		}
	$login_array["login_name"]=$_POST["farmer_name"];
	$login_array["password"]="1234";
	$db->query=generateInsertQuery("login_details", $login_array);
	$db->runQuery();
		
	$db->query="COMMIT";
	$db->runQuery();
	}
$page=new cPage();
$page->title="முதல் முறை மட்டும் பதிவு செய்ய விபரங்கள்";
$page->heading="முதல் முறை மட்டும் பதிவு செய்ய விபரங்கள்";
$page->doHeaderHtml();
$page->doCentreHtml();

$form=new cForm();
$report=new cReport();


$form->properties=array("name"=>"registration","action"=>"register.php","method"=>"POST");
echo $form->startForm();
$form->properties=array("type"=>"text","class"=>"textm","name"=>"farmer_name","value"=>"$farmer_name", "size"=>"25","maxlength"=>"50");
$registration_form[0]["முழுப் பெயர்"]=$form->generateInputTag();

$form->properties=array("type"=>"text","class"=>"textm","name"=>"farmer_address","value"=>"$farmer_address", "size"=>"50","maxlength"=>"75");
$registration_form[0]["முகவரி"]=$form->generateInputTag();

$form->properties=array("type"=>"text","class"=>"textm","name"=>"farmer_village","value"=>"$farmer_village", "size"=>"50","maxlength"=>"75");
$registration_form[0]["கிராமம்"]=$form->generateInputTag();


$city_array[0]["name"]="சென்னை";
$city_array[0]["id"]="1";
$form->properties=array("name"=>"city_id","Class"=>"textm");
$form->select_tag_properties=array("default"=>$_POST["city_id"],"arrays"=>$city_array,"restore_default"=>$_POST["city_id"]);
$registration_form[0]["நகரம்"]=$form->generateSelectTag().$dv->errors["city_id"];


$state_array[0]["name"]="tn";
$state_array[0]["id"]="tn";
$form->properties=array("name"=>"state_id","Class"=>"textm");
$form->select_tag_properties=array("default"=>$_POST["state_id"],"arrays"=>$state_array,"restore_default"=>$_POST["state_id"]);
$registration_form[0]["மாநிலம்"]=$form->generateSelectTag().$dv->errors["city_id"];

$form->properties=array("type"=>"text","class"=>"textm","name"=>"phone_no","value"=>"$phone_no", "size"=>"10","maxlength"=>"15");
$registration_form[0]["தொலைபேசி"]=$form->generateInputTag();

$report->data=$registration_form;
$report->customization["table_style"]="width:30%; border-style:none; border-width:0;";
$report->customization["tr_style"]="border-style:none; border-width:0;";
$report->highlight=false;
echo "<div align=\"center\">";
$report->doVerticalTable();

	$city_array[0]["name"]="சென்னை";
	$city_array[0]["id"]="சென்னை";
	$state_array[0]["name"]="tn";
	$state_array[0]["id"]="tn";
	$uom_array[0]["name"]="acre";
	$uom_array[0]["id"]="acre";
	$land_type_array[0]["name"]="நஞ்செய்";
	$land_type_array[0]["id"]="நஞ்செய்";

for ($i=0;$i<5;  $i++)
	{
	$form->properties=array("type"=>"text","class"=>"textm","name"=>"land_no[$i]","value"=>"$land_no[$i]", "size"=>"12","maxlength"=>"35");
	$land_form[$i]["வரிசை எண்"]=$form->generateInputTag();

	$form->properties=array("type"=>"text","class"=>"textm","name"=>"land_name[$i]","value"=>"$land_name[$i]", "size"=>"15","maxlength"=>"50");
	$land_form[$i]["நிலத்தின் பெயர்"]=$form->generateInputTag();

	$form->properties=array("type"=>"text","class"=>"textm","name"=>"land_address[$i]","value"=>"$land_address[$i]", "size"=>"20","maxlength"=>"75");
	$land_form[$i]["முகவரி"]=$form->generateInputTag();

	$form->properties=array("type"=>"text","class"=>"textm","name"=>"land_village[$i]","value"=>"$land_village[$i]", "size"=>"10","maxlength"=>"15");
	$land_form[$i]["கிராமம்"]=$form->generateInputTag();


	$form->properties=array("name"=>"land_city[$i]","Class"=>"textm");
	$form->select_tag_properties=array("default"=>$_POST["land_city"][$i],"arrays"=>$city_array,"restore_default"=>$_POST["land_city"][$i]);
	$land_form[$i]["நகரம்"]=$form->generateSelectTag().$dv->errors["land_city"][$i];

	$form->properties=array("name"=>"land_state[$i]","Class"=>"textm");
	$form->select_tag_properties=array("default"=>$_POST["land_state"][$i],"arrays"=>$state_array,"restore_default"=>$_POST["land_state"][$i]);
	$land_form[$i]["மாநிலம்"]=$form->generateSelectTag().$dv->errors["land_state"][$i];

	$form->properties=array("type"=>"text","class"=>"textm","name"=>"land_size[$i]","value"=>"$land_size[$i]", "size"=>"10","maxlength"=>"15");
	$land_form[$i]["நில அளவு"]=$form->generateInputTag();

	$form->properties=array("name"=>"size_uom[$i]","Class"=>"textm");
	$form->select_tag_properties=array("default"=>$_POST["size_uom"][$i],"arrays"=>	$uom_array,"restore_default"=>$_POST["size_state"][$i]);
	$land_form[$i]["அளவை"]=$form->generateSelectTag().$dv->errors["size_uom"][$i];

	$form->properties=array("name"=>"land_type[$i]","Class"=>"textm");
	$form->select_tag_properties=array("default"=>$_POST["land_type"][$i],"arrays"=>	$land_type_array,"restore_default"=>$_POST["land_type"][$i]);
	$land_form[$i]["நில வகை"]=$form->generateSelectTag().$dv->errors["land_type"][$i];
	}
	
	$report->data=$land_form;
	$report->customization["table_style"]="width:90%; border-style:none; border-width:0;";
	$report->customization["tr_style"]="border-style:none; border-width:0;";
	$report->highlight=false;
	echo "<div align=\"center\">";
	$report->doHorizontalTable();
$form->properties=array("name"=>"save","type"=>"submit","value"=>"OK");
echo $form->generateInputTag();
echo $form->endForm();


$page->doFooterHtml();
?>
